﻿using AnyCAD.Foundation;
using AnyCAD.NX.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AnyCAD.SourceGenerator.Common;

namespace AnyCAD.Modeling.Sphere
{
    public enum EnumSphereStep
    {
        None,
        Center
    }

    public partial class SphereViewModel : ComponentViewModel
    {        
        public SphereModel Model { get { return (SphereModel)_Model; } }
        public SphereViewModel(Element model, GeneralComponent component, MainViewModel doc)
            : base(new SphereModel(), model, component, doc)
        {
            SetCurrentStep(nameof(Center));
        }

        public double Diameter 
        { 
            get => Model.Diameter; 
            set => SetProperty(nameof(Diameter), ref Model.Diameter, value); 
        }

        [StepStateBinding]
        public EnumSphereStep _PickStepIndex = EnumSphereStep.None;

        [ExpandXYZ]
        public GPnt Center
        {
            get => Model.Center;
            set => SetProperty(nameof(Center), ref Model.Center, value, nameof(CenterX), nameof(CenterY), nameof(CenterZ));
        }


        public override void ResetSteps()
        {
            base.ResetSteps();

            OnPropertyChanged(nameof(CenterX), nameof(CenterY), nameof(CenterZ), nameof(Diameter));
        }

        public override void OnViewSelectionChanged(PickedResult pr, GPnt? pt)
        {
            if(pt != null)
            {
                Center = pt;
               
            }
            else
            {
                if (pr.IsEmpty())
                    return;

                Center = pr.GetItem().GetPosition().ToPnt();
            }
            SetStepState(nameof(Center), true);
        }
    }
}
